package com.leetcode.Offer;

public class JZ46_2 {
    public static int translateNum(int num) {
        char[] chars = String.valueOf(num).toCharArray();
        int[] dp = new int[chars.length];

        dp[0] = 1;
        for (int i = 1; i < chars.length; i++) {
            if (chars[i] == '0') {
                if (chars[i - 1] == '1' || chars[i - 1] == '2') {
                    dp[i] = dp[i - 1] + dp[Math.max(i - 2, 0)];
                } else {
                    dp[i] = dp[i - 1];
                }
            } else if (chars[i - 1] == '1') {
                dp[i] = dp[i - 1] + dp[Math.max(i - 2, 0)];
            } else if (chars[i - 1] == '2') {
                if (chars[i] > '0' && chars[i] < '6') {
                    dp[i] = dp[i - 1] + dp[Math.max(i - 2, 0)];
                } else {
                    dp[i] = dp[i - 1];
                }
            } else {
                dp[i] = dp[i - 1];
            }
        }
        return dp[chars.length - 1];
    }

    public static void main(String[] args) {
        System.out.println(translateNum(12258));
    }
}
